package it.univaq.mwt.facade;

import java.io.IOException;
import java.util.List;
import it.univaq.mwt.business.GroupsService;
import it.univaq.mwt.exceptionmonitor.WishListrException;
import it.univaq.mwt.exceptionmonitor.WishlistUserException;
import it.univaq.mwt.exceptionmonitor.LivelloEx;
import it.univaq.mwt.exceptionmonitor.WishlistrMessage;
import it.univaq.mwt.log.LivelloLog;
import it.univaq.mwt.log.LogManager;
import it.univaq.mwt.model.bean.GroupsBeanRemote;
import it.univaq.mwt.model.entity.Groups;



public class FacadeGroups implements GroupsService,LivelloEx, LivelloLog {

	private GroupsBeanRemote gbr;
	

	public FacadeGroups(GroupsBeanRemote gbr) {
		super();
		this.gbr = gbr;
	}


	
	public List<Groups> getGroupList() {
		
		List<Groups> listGroups=null;
		try{
			listGroups=gbr.getGroupList();
			
			LogManager.getIstance().scrivi("FacadeGroup - getGroupList" , RUN);			
		} catch (IOException e) {
			new WishListrException(e,ERROR);
		}catch(NullPointerException e){
			new WishListrException(e,ERROR);
		} catch (Exception e) {
			new WishListrException(e,ERROR);
		}
		return listGroups;
		
	}

	
	public Groups getGroup(int id) {

		Groups group=null;
		try{
			group=gbr.getGroup(id);
			LogManager.getIstance().scrivi("FacadeGroup - getGroup: Richiesta del gruppo id " + id, RUN);
		}catch(Exception e){
			new WishListrException(e,ERROR);
		}
		return group;
	}


	
	public Groups addGroup(Groups logged) throws WishlistUserException {
		
		Groups group=null;
		
		try{
			try {
				group=gbr.addGroup(logged);
			} catch (WishlistrMessage e) {
				LogManager.getIstance().scrivi("FacadeNews - deleteNews " + e.getMessage(), ERR);
			// throws
			}
			
			LogManager.getIstance().scrivi("FacadeGroup - addGroup: Richiesta aggiunta del gruppo id ", RUN);
		} catch (IOException e) {
			new WishListrException(e,ERROR);
		}catch(RuntimeException e){
			new WishListrException(e,ERROR);
		}
		
		return group;
	}
}